package com.zlx.guguanjia.controller;

import com.zlx.guguanjia.entity.AppVersion;
import com.zlx.guguanjia.entity.Result;
import com.zlx.guguanjia.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName AppVersionController
 * @date 2020.10.22 17:44:21
 * 该版权归周罗校所有，最终解释权以官方为准
 */

@CrossOrigin
@RestController
@RequestMapping("/manager/app")
public class AppVersionController {
    @Autowired
    public AppVersionService appVersionService;

    @RequestMapping({"/index","/index.html"})
    public ModelAndView index(){
        return new ModelAndView("/app/index.html");
    }

    @GetMapping("listAll")
    public Result listAll(){
        //返回所有app上线情况sout
        return new Result(appVersionService.selectAll());
    }

    @GetMapping("selectPage")
    public Result selectPage(int start,int pageSize){
        //返回分页数据
        return new Result(appVersionService.selectPage(start,pageSize));
    }
    //更新
    @PutMapping("updateAppInfo")
    public Result updateAppInfo(@RequestBody AppVersion app){
        //更新修改时间
        app.setUpdateDate(new Date());
        //返回分页数据
        return new Result(appVersionService.updateByPrimaryKeySelective(app));
    }
    //逻辑删除
    @PutMapping("deleteAppVersionById")
    public Result deleteAppVersionById(@RequestBody Map<String,String> map){
        //返回分页数据
        return new Result(appVersionService.deleteAppVersionById(Long.valueOf(map.get("id"))));
    }

    //插入新的版本数据
    @PostMapping("insertAppVersion")
    public Result insertAppVersion(@RequestBody AppVersion app){
        //返回分页数据
        return new Result(appVersionService.insertAppVersion(app));
    }
}
